<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>件号工时数据查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'件号工时数据查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="工艺版本:">
          <el-select v-model="queryInfo.selecttype" placeholder="请选择">
            <el-option :key="'最新工艺'" :label="'最新工艺'" :value="'最新工艺'"></el-option>
            <el-option :key="'默认工艺'" :label="'默认工艺'" :value="'默认工艺'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工艺创建时间:">
          <el-date-picker v-model="queryInfo.createdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData()">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="零件图号" width="120" prop="productname" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件版本" prop="productrevision" width="120"></el-table-column>
        <el-table-column label="工艺名称" prop="process_no" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="工艺版本" prop="workflowrevision" width="100"></el-table-column>
        <el-table-column label="工艺创建时间" prop="lastchangedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="工序号" prop="specno" width="100"></el-table-column>
        <el-table-column label="工序名称" prop="opdesc" width="140"></el-table-column>
        <el-table-column label="作业人数" prop="makeempcounts" width="80"></el-table-column>
        <el-table-column label="工区" prop="workcentername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="班组" prop="teamname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="准备工时" prop="preparecycle" width="80"></el-table-column>
        <el-table-column label="加工工时" prop="makecycle" width="80"></el-table-column>
        <el-table-column label="转运工时" prop="transfercycle" width="80"></el-table-column>
        <el-table-column label="转工周期" prop="shipcycle" width="80"></el-table-column>
        <el-table-column label="外委周期" prop="commicycle" width="80"></el-table-column>
        <el-table-column label="设备" prop="resourcename" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="装炉/槽量" prop="chargingqty" width="80"></el-table-column>
        <el-table-column label="工序类型" prop="spectype" width="100"></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[14,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryid: '',
          productname: '',
          selecttype: '最新工艺',
          createdate: '',
          currentPage: 1,//当前页
          pageSize: 14//每页显示条数
        },
        factoryList: [],
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        //查询数据
        async getData(currentpage) {
          if (this.queryInfo.createdate.length > 0 && this.queryInfo.selecttype === '默认工艺') {
            return this.$message.error('工艺创建时间不为空时，工艺版本必须选择【最新工艺】');
          }
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/WorkflowstepWorkTimeQueryReport.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg);
          }
          this.dataList = data;
          this.total = total;
        },
        // 导出excel
        async getExportExcel() {
          if (this.queryInfo.createdate.length > 0 && this.queryInfo.selecttype === '默认工艺') {
            return this.$message.error('工艺创建时间不为空时，工艺版本必须选择【最新工艺】');
          }
          const config = {
            url: '../handler/report/WorkflowstepWorkTimeQueryReport.ashx?action=exportExcel',
            data: {
              type: 'exportExcel',
              ...this.queryInfo,
              factoryname: this.factoryname
            }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>